using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Little_Tower_Defense.Interfaces;
using Little_Tower_Defense.Controller;


namespace Little_Tower_Defense.DrawableComponents
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class Button : Microsoft.Xna.Framework.DrawableGameComponent, IClickable
    {
        private Rectangle Area;
        private Color BackgroundColor;
        private Texture2D BackgroundTexture;
        private SpriteBatch spriteBatch;

        public Button(Game game, int X, int Y): base(game)
        {
            MouseController.AddListener(this);
            this.Area = new Rectangle(X,Y,50,20);
            this.BackgroundColor = Color.Red;
            this.DrawOrder = 3;
            
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            this.BackgroundTexture = Game.Content.Load<Texture2D>("UIElements\\Background");
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);
            base.Initialize();
        }

        protected override void LoadContent()
        {
            this.BackgroundTexture = Game.Content.Load<Texture2D>("UIElements\\Background");
        }

        public override void Update(GameTime gameTime)
        {
            MouseState newState = Mouse.GetState();
            this.BackgroundColor = new Color(255, 90, 20);
            if (GetArea().Intersects(new Rectangle(newState.X, newState.Y, 10, 10)))
            {
                this.BackgroundColor = Color.Red;
            }

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            if (this.Visible == true)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(BackgroundTexture, this.Area, this.BackgroundColor);
                spriteBatch.End();
            }
        }

        public Rectangle GetArea()
        {
            return (Area);
        }

        void IClickable.Click(MouseState state)
        {

        }

        void IClickable.Release()
        {
        
        }
    }
}
